const puppeteer = require('puppeteer');
const items = require('./pagetest2');
const EventEmitter = require('events').EventEmitter;
EventEmitter.defaultMaxListeners = 100;

const get_list = async(url) => {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    await page.goto(url);
    const times = await page.evaluate(() => {
        const time = document.querySelectorAll('body');
        //const detial = document.querySelectorAll('#position_as_type_c0 tbody td');
        return Array.from(time, body => body.innerText);
    });

    const obj = await eval("(" + times + ")")
    const obj_timeLine = obj['timeLine'];
    for (item in obj_timeLine) {
        await items(obj_timeLine[item]);
    }

    await console.log('is ok!');
    await browser.close();
};
///////////////////////////////////////
module.exports = get_list;
if (require.main === module) {
    const url = 'https://gupiao.baidu.com/api/stocks/stocktimeline?from=pc&os_ver=1&cuid=xxx&vv=100&format=json&stock_code=sh601989&timestamp=1509939795418'
        //var interval = setInterval(() => {
    get_list(url);
    //}, 2000);
    //setTimeout(() => {
    //   clearInterval(interval)
    // }, 10000);





}